/**
 * 
 */
package com.estock.platform.http.response;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.estock.common.model.security.Index;
import com.estock.common.model.security.enums.StockType;

/**
 * @author richard
 *
 */
public class SinaIndexBulkResponse extends SinaBaseResponse {
	
	List<Index> indexes = new ArrayList<Index>();
	public List<Index> getIndexes() {
		return indexes;
	}
	
	/**
	 * 	Returned string is not json format, it's something like
	 *	var hq_str_s_sh000010="上证180,10024.26,237.633,2.43,1777574,23076873";
	 *	var hq_str_s_sz399001="深证成指,13933.909,287.302,2.11,227674680,28603178";
	 * 
	 * @param sinaJsString
	 */
	@Override
	protected void parse(String sinaJsString) {
		parameters.clear();
		
		if (StringUtils.isEmpty(sinaJsString)) {
			throw new RuntimeException();
		}
		String[] tempArr = sinaJsString.split("=");
		String[] values = tempArr[1].replace("\"", "").split(",");
		
    	Index index = new Index();
    	index.setCode(tempArr[0].substring(tempArr[0].length() - 6, tempArr[0].length()));
    	index.setType(Integer.valueOf(StockType.getStockTypeByAbbr(tempArr[0].substring(tempArr[0].length() - 8, tempArr[0].length() - 6))));
    	index.setName(values[0]);
    	index.setLatestPrice(Float.valueOf(values[1]));
		
		indexes.add(index);
	}
	
}
